Page({
  data: {
    scrollbar: 200,
    scrollTop: 0,
    scrollbarConfig: {
      maxHeihgt: 200,
      lineHeight: 32,
    },
    showPlaceholder: true
  },
  onLoad(){
   
  },

  onShareAppMessage(){
    
  },

  getTextarea(){
    this.getElScrollInfo(".textarea", res => {
      console.log(res);
    });
  },

  onScroll(e){
    const td = this.data, ed = e.detail, sc = td.scrollbarConfig;
    console.log('yes');
    if (ed.scrollTop + 30 < sc.maxHeihgt){
      this.setData({
        scrollTop: ed.scrollTop
      });
    }else{
      this.setData({
        scrollTop: sc.maxHeihgt - 35
      });
    }

      
  },

  textareaLineChange(e){
    const td = this.data, ed = e.detail, sc = td.scrollbarConfig;

    if (ed.heightRpx > sc.maxHeihgt){
      let scrollbar_val = sc.maxHeihgt - sc.lineHeight * (ed.lineCount - 5);

      if (scrollbar_val > 35){
        this.setData({
          scrollbar: scrollbar_val
        });
      }
    }else{
      this.setData({
        scrollbar: sc.maxHeihgt
      });
    }
  },

  editorInput(e){
    const td = this.data, ed = e.detail;
    
    this.setData({
      editorVal: ed.text.trim()
    });
    console.log(ed.text);
  },

  getElScrollInfo(name, callback){
    let query_el = wx.createSelectorQuery();
    let textarea = query_el.select(name).boundingClientRect();
  
    textarea.selectViewport().scrollOffset();
    textarea.exec(res => {
      callback(res);
    });
  }
})